
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/04/2012 18:13:45
-- Generated from EDMX file: C:\Users\Tee\Documents\Visual Studio 2010\Projects\VLUSM_Project\VLUSM_DataAccess\Diem.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [VLUSM];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MonHocDiem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Diem] DROP CONSTRAINT [FK_MonHocDiem];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Diem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Diem];
GO
IF OBJECT_ID(N'[dbo].[MonHoc]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MonHoc];
GO
IF OBJECT_ID(N'[dbo].[SinhVienNoMon]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SinhVienNoMon];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Diem'
CREATE TABLE [dbo].[Diem] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [MaSinhVien] nvarchar(7)  NOT NULL,
    [NamHoc] int  NULL,
    [HocKy] nvarchar(max)  NULL,
    [KetQua] float  NOT NULL,
    [Diem1] float  NULL,
    [Diem2] float  NULL,
    [DiemBT] float  NULL,
    [DiemTL] float  NULL,
    [DVHT] int  NULL,
    [MonHocID] int  NOT NULL
);
GO

-- Creating table 'MonHoc'
CREATE TABLE [dbo].[MonHoc] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [MaMonHoc] nvarchar(max)  NOT NULL,
    [SoDVHT] int  NULL,
    [NhomNguoiDung] nvarchar(max)  NULL,
    [NgayCapNhat] datetime  NULL,
    [NguoiCapNhat] nvarchar(max)  NULL,
    [NgayTao] datetime  NULL,
    [NguoiTao] nvarchar(max)  NULL,
    [TenGoi] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'SinhVienNoMon'
CREATE TABLE [dbo].[SinhVienNoMon] (
    [MonHocID] int IDENTITY(1,1) NOT NULL,
    [SinhVienID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Diem'
ALTER TABLE [dbo].[Diem]
ADD CONSTRAINT [PK_Diem]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MonHoc'
ALTER TABLE [dbo].[MonHoc]
ADD CONSTRAINT [PK_MonHoc]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [MonHocID], [SinhVienID] in table 'SinhVienNoMon'
ALTER TABLE [dbo].[SinhVienNoMon]
ADD CONSTRAINT [PK_SinhVienNoMon]
    PRIMARY KEY CLUSTERED ([MonHocID], [SinhVienID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [MonHocID] in table 'Diem'
ALTER TABLE [dbo].[Diem]
ADD CONSTRAINT [FK_MonHocDiem]
    FOREIGN KEY ([MonHocID])
    REFERENCES [dbo].[MonHoc]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MonHocDiem'
CREATE INDEX [IX_FK_MonHocDiem]
ON [dbo].[Diem]
    ([MonHocID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------